package com.itheima.demo002;

public class homework003 {
    public static void main(String[] args) {
        /*
        作业  1
        for (int i = 1949; i < 2019; i++){
            if ((2019 - i) % 12 == 0){
                System.out.println(i);
                System.out.println("猪年");
            }
        }
        */

        /*
        作业  2
        for (int i = 1988 ; i <= 2019 ; i++){
            if (i % 4 == 0 && i % 100 != 0 || i % 400 == 0){
                System.out.println(i + "闰年");
            }
        }
        */
/*      作业  3
        int[] arr = {1,2,3,4,5};
        for (int i = 0; i <= 4; i++) {
            System.out.print(arr[i] + " ");
        }

*/

    /*      作业  4
    double[] arr = {12.9, 53.54, 75.0, 99.1, 3.14};
    double min = arr[0];
        for (int i = 1; i < arr.length; i++) {
            if(arr[i] < min){
                min = arr[i];
            }
        }
        System.out.println("最小值是" + min);
    */
        /*  作业  5
        Random r = new Random();
        int[] arr = new int[6];
        for (int i = 0; i < arr.length; i++) {
            int number = r.nextInt(100);
            System.out.print(number + " ");
            arr[i] = number;
        }
        int sum = 0;
        for (int i = 0; i < arr.length; i++) {
            sum += arr[i];
        }
        System.out.println("和是：" + sum);
        */

        /*  作业  6
        int[] arr = {2,1,3,5,4};
        int num = 0;
        for (int i = 0; i < arr.length; i++) {
            num = num * 10 + arr[i];
        }
        System.out.println(num);
        */

        /*  作业  7
        int[] arr = {72, 89, 65, 87, 91, 82, 71, 93, 76, 68};
        double sum = 0;
        for (int i = 0; i < arr.length; i++) {
            sum = sum + arr[i];
            //sum += arr[i];
        }
        double avy = sum / arr.length;
        System.out.println(sum);
        System.out.println("平均值是：" + avy);
        */

       /*   作业  8
//1.定义长度为10的原数组
        int[] arr = {12,14,23,45,66,68,70,77,90,91};
//2.定义长度为11的空数组
        int[] brr = new int[11];
//3.键盘录入数组
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入一个整数");
        int number = sc.nextInt();
//4.定义变量代表要插入的位置
        int index = 0;
//5.循环遍历原数组
        for (int i = 0; i < arr.length; i++) {
            if(arr[i] <= number){
//5.1如果元素小于等于要插入的数字，则直接存放
                brr[i] = arr[i];
//5.2把i后面的位置记录下来
                index = i + 1;
            }
            else{
//5.3如果元素大于要插入的数字,则往后一个位置存放
                brr[i + 1] = arr[i];
            }
        }
//6.index存储的就是要插入的位置
        brr[index] = number;
//7.遍历新数组查看结果
        System.out.println("生成的新的数组是：");
        for (int i = 0; i < brr.length; i++) {
            System.out.print(brr[i] + " ");
        }
        */
//1.定义原数组
        int[] arr = {12,23,34,45,67,78,11,22};
//2.定义空数组
        int[] brr = new int[arr.length];
//3.定义变量代表奇数要存放的位置
        int left = 0;
//4.定义变量代表偶数要存放的位置
        int right = arr.length - 1;
//5.对原数组进行遍历
        for (int i = 0; i < arr.length; i++) {
            if(arr[i] % 2 == 1){
//5.1如果是奇数就往左边放
                brr[left] = arr[i];
//5.2存放之后让索引向右移动
                left++;
            }
            else{
//5.3如果是偶数就往右边放
                brr[right] = arr[i];
//5.4存放之后让索引向左移动
                right--;
            }
        }
//6.打印brr数组
        for (int i = 0; i < brr.length; i++) {
            System.out.print(brr[i] + " ");
        }
    }
}
